Fixing: jump to caret does not keep a correct stack when there are vector arrays to store common variables between methods and blocks #78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #55
When we jump to caret to a node inside a block, we go to first pc of the first statement and we skip until the block creation to step it in order to get the created closure. Creating the closure requires to push a temp vector on the stack. This temp vector is not mapped to the AST block, but to the node preceding the block.
If the block creation is the first bytecode in the first statement in the method, then this pushVector bytecode is mapped to the method node. However, we skip all bytecodes mapped to the method node because otherwise it would recreate all temps and that's not what we want when we perform
jumpToCaret:
.So, if we perform a jumpToCaret to go into a block that whose creation is the first bytecode in the first statement, then the pushVector bytecode is not executed. As a result, it messes up the stack in both contexts which will ultimately lead to errors.
I fixed this behavior so that, when we go back to the first pc of the first statement, if the associated bytecode is a block creation, I go back to the previous bytecode (which is the pushVector bytecode) to step it to ensure that the stack is correct.